<table width="100%" height="100px">
	<tr><td>
		<table width="100%" border=1 bgcolor="#ffffff">
			<tbody><tr><td><h4>权限分配操作</h4></td></tr></tbody>
			<tr><td>请选择需分配权限的角色<div id="div.authrole.role" /></td></tr>
		 	<tr><td>请选择扩展权限<div id="div.authdyna.role"/></td></tr>
		 	<tr><td>请选择要分配的权限类型<div id="div.authkind.role"/></td></tr>
		 	<tr><td align="center"><input type="button" id="auth.save.role" name="auth.save.role" value="确定"></td></tr>
		 </table>
		 
		</td>
	    <td valign="top">
	    	角色拥有该节点的权限<span><a href="#" id="auth.del.role" name="auth.del.role">删除</a></span> 
		 	<div id="div.authhave.role">
		</td>
 	</tr>
</table>
 

<script type="text/javascript">
var dataURL = '/data/sc.action';//取数据的url

//-------------填充角色-------- 
var allroles;
var allroles_pageno = 1;
if (allroles) { allroles_pageno = allroles.findCurrentPage(); }
var loadAllRolesList = function(){
	dataURLParams = {"scid":"authroleinfos_2"}; 
	var columns = [{text:'序号',name:'id'},{text:'角色名',name:'name'},{text:'说明',name:'note'}];//要显示的字段
	if (!allroles){
		allroles = new MUI.List({
			instanceName: 'allroles',
	       	container:'div.authrole.role',
	       	showCheckBox:true,
			showCommand:false,
	       	id: 'authALLRoleList',
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams:dataURLParams,
	       	cbName: 'idsAllRole',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	allroles.setDataURLParams(dataURLParams);
   	allroles_pageno = 1;
   	allroles.findList(allroles_pageno);
}

//-------------填充扩展权限-------- 
var dynanode;
var dynanode_pageno = 1;
if (dynanode) { dynanode_pageno = dynanode.findCurrentPage(); }

var loadAuthDynanodeList = function(){

	var columns = [{text:'扩展权限',name:'pcol'},{text:'扩展说明',name:'vcol'}];//要显示的字段
	var dataURLParams = {"scid":"authnodedyna", "authid":nodeinfo.id};
	if (!dynanode){
		dynanode = new MUI.List({
			instanceName: 'dynanode',
	       	container:'div.authdyna.role',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "adynanodeList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsDynanode',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	dynanode.setDataURLParams(dataURLParams);
   	dynanode_pageno = 1;
   	dynanode.findList(dynanode_pageno);
}

//-------------填充权限类型 
var authKind;
var authKind_pageno = 1;
if (authKind) { authKind_pageno = authKind.findCurrentPage(); }

var loadAuthKindList = function(){
	var columns = [{text:'权限代号',name:'kind'},{text:'权限类型',name:'name'}];//要显示的字段
	var dataURLParams = {"scid":"authkind_1"};
	if (!authKind){
		authKind = new MUI.List({
			instanceName: 'authKind',
	       	container:'div.authkind.role',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "authkindList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsAuthkind',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	authKind.setDataURLParams(dataURLParams);
   	authKind_pageno = 1;
   	authKind.findList(authKind_pageno);
}


//填充该节点有哪些角色,及角色拥有的权限
var authhave;
var authhave_pageno = 1;
if (authhave) { authhave_pageno = authhave.findCurrentPage(); }

var loadAuthhaveList = function(){
	var columns="";
	var dataURLParams = "";
	if( 0==nodeinfo.kind ){
		columns = [{text:'序号',name:'id'},{text:'角色名',name:'rolename'},{text:'权限类型',name:'kindname'}];//要显示的字段
		dataURLParams = {"scid":"authroleinfos_1", "authid":nodeinfo.id};
	}else{  
		columns = [{text:'序号',name:'id'},{text:'扩展字段',name:'vcolvalue'},{text:'角色名',name:'rolename'},{text:'权限类型',name:'kindname'}];//要显示的字段
		dataURLParams = {"scid":"authroleinfos_dyna", "authid":nodeinfo.id};
	}
	if (!authhave){
		authhave = new MUI.List({
			instanceName: 'authhave',
	       	container:'div.authhave.role',
	       	showCheckBox:true,
			showCommand:false,
	       	id: "authhaveList",
	       	columns:columns,
	       	dataURL:dataURL,
	       	dataURLParams: dataURLParams,
	       	cbName: 'idsauthhave',
	       	saveCheck:true,
	       	commands:[],
	       	onItemCommand: function(item,self,cmd,img) {},
	       	onItemChecked: function(item,self,cmd,img) {},
	       	onItemSelected: function(item,self,cmd,img) {},
	       	onItemColumnBound: function(item,self,col,td) {}
	   	});//MUI.List
   	}
   	authhave.setColumns(columns);
   	authhave.setDataURLParams(dataURLParams);
   	authhave_pageno = 1;
   	authhave.findList(authhave_pageno);
}



window.addEvent('domready', function() {
	new MUI.Require({
	  js: [MUI.path.plugins + 'mochaList/List.js'],
	  onload: function(){
		if(nodeinfo==null){
			MUI.notification('<font color=red>错误：</font> 未取得节点信息 ');
			return;
		}
		loadAllRolesList();
		if(1==nodeinfo.kind)
			loadAuthDynanodeList();
		loadAuthKindList(); 
		loadAuthhaveList();
		
	  } 
	}); 
	
	
	$('auth.save.role').addEvent('click', function(e){
		if(!allroles || !authKind) return;
		var checkids_dynanode = "";
		var dataURLParams = ""; 
		var checkids_roles = allroles.getcurCheckIds();
		var checkids_kinds = authKind.getcurCheckIds();
		checkids_roles = checkids_roles + "";
		checkids_kinds = checkids_kinds + "";
		if(null==checkids_roles || ""==checkids_roles) { alert('必须选择一项要添加的角色'); return; }
		if(null==checkids_kinds || ""==checkids_kinds) { alert('必须选择一项要添加的权限种类'); return; }
		if(1==nodeinfo.kind){
			if(!dynanode) return;
			checkids_dynanode = dynanode.getcurCheckIds();
			if(null==checkids_dynanode || ""==checkids_dynanode) { alert('必须选择一项要添加的扩展权限'); return; }
			checkids_dynanode = checkids_dynanode + "";
			dynanode.clearCheckIds();
		}
		dataURLParams = {"scid":"authroleinfos_3", "checkids_roles":checkids_roles, 
			"checkids_kinds":checkids_kinds, "checkids_dynanode":checkids_dynanode, 
			"authkind":nodeinfo.kind, "authid":nodeinfo.id};
		allroles.clearCheckIds();
		authKind.clearCheckIds();
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('添加成功！');
    				loadAuthhaveList();
    				//取消所有选中的勾选
    				allroles.cancelAll();
    				authKind.cancelAll();
    				if(1==nodeinfo.kind) dynanode.cancelAll();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
	
	$('auth.del.role').addEvent('click', function(e){
		if(!authhave) return;
		checkids_authhave = authhave.getcurCheckIds();
		if(null==checkids_authhave || ""==checkids_authhave) { alert('必须选择一项要删除的角色权限'); return; }
		checkids_authhave = checkids_authhave + "";
		authhave.clearCheckIds();
		var dataURLParams = {"scid":"authroleinfos_4", "authkind":nodeinfo.kind, "checkids_authhave":checkids_authhave};
		try {
			var request = new Request.JSON({
			url: dataURL,
			onComplete: function(json,text) {
				if (json.error.errorcode==0){
    				MUI.notification('删除成功！');
    				loadAuthhaveList();
    				//取消所有选中的勾选
    				authhave.cancelAll();
    			}else{
    				MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
    			}
			}
		}).get(dataURLParams);
		} catch (ex) {
			MUI.notification('<font color=red>错误：</font>('+json.error.retstring+')');
		}
	});
});
</script>